package cn.laixueit.controller;

import cn.laixueit.pojo.Cart;
import cn.laixueit.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

@Controller
public class CartController {

    @Autowired
    private CartService cartService;

    @PostMapping("/cart")
    public ResponseEntity<Void> cart(@RequestBody Cart cart){

        cartService.addCart(cart);

        return ResponseEntity.status(HttpStatus.OK).build();
    }

    @GetMapping("/findCartList")
    public ResponseEntity<List<Cart>> findCartList(){
        List<Cart> cartList = cartService.findCartList();
        return ResponseEntity.ok(cartList);
    }

}
